<template>
  <div>
    <div :style="btnStyle" class="btn-text" @click="getProcess">{{ btnText }}</div>
    <el-dialog
      :visible.sync="dialogVisible"
      :before-close="handleClose"
      :append-to-body="true"
      :class="{'mobile-el-dialog': showMobilePage}"
      class="open-invoice-common-dialog medium-common-dialog-size"
      width="640px">
      <Title title="结算进度" font-size="16px" style="margin-bottom: 10px" />
      <div class="dialog-main">
        <el-table
          v-loading="loading"
          v-if="processData.length"
          :data="processData"
          :max-height="tableHeight"
          element-loading-text="加载中..."
          empty-text="暂无数据"
          header-cell-class-name="order-data-header-cell"
          fit
          hightlight-current-row>
          <el-table-column align="left" label="成本名称" >
            <template slot-scope="scope">
              <span>{{ scope.row.costName || '--' }}</span>
            </template>
          </el-table-column>
          <el-table-column align="left" label="成本" width="80">
            <template slot-scope="scope">
              <span>{{ (scope.row.costPrice / 100) | moneyFilter }}</span>
            </template>
          </el-table-column>
          <el-table-column align="left" label="结算状态" width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.status | statusFilter }}</span>
            </template>
          </el-table-column>
          <el-table-column align="left" label="结算单号">
            <template slot-scope="scope">
              <el-tooltip v-if="scope.row.supplierNum" class="item" placement="top" effect="dark">
                <div slot="content" style="max-width: 200px;">{{ scope.row.supplierNum }}</div>
                <div class="ellipsis" style="cursor:pointer;color:#406EFF;" @click="toSuppler(scope.row)">{{ scope.row.supplierNum }}</div>
              </el-tooltip>
              <div v-else>--</div>
            </template>
          </el-table-column>
        </el-table>
        <empty-placeholder v-else :empty-img="emptyImg" :image-size="'100px'" style="margin-bottom: 24px" />
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getOrderProcess } from '@/api/supplier';
import emptyImg from '@/assets/empty-data-icon.png';
import Title from '@/components/Title';
import EmptyPlaceholder from '@/components/EmptyPlaceholder';
import { moneyFilter } from '@/filters/number';
import { mapState } from 'vuex';
export default {
  components: { Title, EmptyPlaceholder },
  filters: {
    moneyFilter,
    statusFilter: (state) => {
      const num = Number(state);
      // 0:成本选择 1:订单选择 2:结算审批 3:结算支付 4: 结算完成
      const arr = ['待结算', '结算完成', '结算中'];
      return arr[num] || '--';
    }
  },
  props: {
    btnText: {
      type: String,
      default: '查看结算'
    },
    btnStyle: {
      type: Object,
      default: () => ({})
    },
    orderId: {
      type: String | Number,
      default: ''
    }
  },
  data() {
    return {
      emptyImg,
      processData: [],
      dialogVisible: false,
      loading: false,
      tableHeight: ''
    };
  },
  computed: {
    ...mapState({
      'showMobilePage': state => state.app.showMobilePage
    })
  },
  methods: {
    getProcess() {
      this.dialogVisible = true;
      const clientHeight = window.innerHeight;
      this.tableHeight = (clientHeight * 4) / 5;
      this.loading = true;
      getOrderProcess({ id: this.orderId }).then(res => {
        this.loading = false;
        if (res.code === 200) {
          this.processData = res.data;
        }
      }).catch(() => {
        this.loading = false;
      });
    },
    handleClose() {
      this.dialogVisible = false;
    },
    toSuppler(item) {
      if (!item.supplierId) return;
      this.handleClose();
      this.$router.push({
        name: 'supplierDetail',
        query: {
          settleId: item.id,
          id: item.supplierId,
          isSettle: true
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.btn-text {
  font-size: 14px;
  color: #406EFF;
  cursor: pointer;
  &:hover {
    color: #1849e7;
  }
}
.supplier-status-list {
  display: flex;
  margin-top: 20px;
  flex-wrap: wrap;
  .supplier-status-item {
    width: 50%;
    margin-bottom: 20px;
    padding-right: 10px;
  }
}
</style>
